package com.xps.and.yuntong.Utils;

import android.content.Context;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

/**
 * 为应用提供一个全局的位置信息
 */
public class GlobalPositionInfo {
    private String TAG = getClass().getSimpleName();
    public LocationClient mLocationClient;
    private BDLocationListener myListener = new GlobalPositionInfo.MyLocationListener();
    public BDLocation bdLocation = null;
    Context mContext;

    public GlobalPositionInfo(Context context) {
        mContext = context.getApplicationContext();
        this.mLocationClient = new LocationClient(context);
        this.mLocationClient.registerLocationListener(myListener);
        initLocation();
    }

    public class MyLocationListener implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            bdLocation = location;
        }


    }

    private void initLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");
        option.setScanSpan(1000 * 5);
        option.setIsNeedAddress(true);
        option.setOpenGps(true);
        option.setLocationNotify(false);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.setIgnoreKillProcess(false);
        option.SetIgnoreCacheException(false);
        option.setEnableSimulateGps(false);
        mLocationClient.setLocOption(option);
        if (!mLocationClient.isStarted())
            mLocationClient.start();


    }


}
